<?php
require ROOT_PATH.'/Helper/front_abstract.php';
require ROOT_PATH.'/Helper/yzm.php';

class Action extends front_abstract
{
	function index(){
	
		if(empty($_SESSION['user'])){
			
			$this->view->display('front/signuped.html');
		}else{
		
			$this->redirect('login/index');
		}
		
	
	}


	function insert(){
	
		
		
		$info = _POST('info', array());

		
		if(empty($info['email'])){
			
			$this->msg('email不能为空!');	    
		
		}


		
		if($info['conf_code']!=$_SESSION['verify']){
			
			$this->msg('验证码错误!');
		}

		 $e = _model('user')->read(array('email'=>$info['email']));

		if($e){
			$this->msg('邮箱已经存在!');
		}
		
		if (filter_var($info['email'], FILTER_VALIDATE_EMAIL) === false) {
	    
	    		$this->msg('邮箱错误!');

		}else{
		   
			$this->send_email($info['email'],'账号激活邮件，请注意查收!',"<a href='".SITE_URL."/register/reg?email=".$info['email']."'>请点击激活账号!".SITE_URL."/register/reg?email=".$info['email']."</a>");
			
			$this->msg('已发送到您的邮箱中请查看邮箱并完成注册!', 'login/index');
			
	  }
	 
	

	}





	function agreen(){

    		$data = _model('agree')->getList();
		$this->view->assign('info',$data[0]['content']);
    		$this->view->display('front/agreen.html');
    	
	}






	


	

	function reg(){

		$email = _GET('email');

		$info= _model('user')->read(array('email'=>$email));
		
		if(!$info){

				$this->view->assign('email',$email);
				$this->view->display('front/signuping.html');
		}else{
		
				$this->msg('sorry,错误!','index.html');
		}
	
	
	}


	function reging(){


		$info = _POST('info', array());


	    if( empty($info['name']) || empty($info['password']) || empty($info['email']) ){
		$this->msg('信息不完整!');	    
	    }

	    if($info['password']!=$info['re_password']){
	    	$this->msg('两次密码不一致');
	    }

	    if($info['conf_code']!=$_SESSION['verify']){
	 	$this->msg('验证码错误!');
	    
	    }

	    $insert = array();
	    
	    if (filter_var($info['email'], FILTER_VALIDATE_EMAIL) === false) {
	    
	    		$this->msg('邮箱错误!');
	    
	    }else{
		    $check_email= _model('user')->read(array('email'=>$info['email']));
		    $check_name= _model('user')->read(array('name'=>$info['name']));

		    if($check_name){
		    
		    	$this->msg('用户名已存在!');
		    }

		    if($check_email){

			 $this->msg('email已存在!');
		    }
			
	    
	    
	    $insert['name'] = $info['name'];
	    $insert['email'] = $info['email'];
	    $insert['activation'] = 0;
	    $insert['is_admin'] = 0;
	    $insert['password'] = md5($info['password']);
	    $insert['add_time'] = time();
	    $id = _model('user')->create($insert);
    		
	  if($id){
		  $user_info= _model('user')->read(array('id'=>$id));	    			
			$_SESSION['user']=$user_info;
			$this->msg('注册成功!','index');
		}else{
	    
	    		$this->msg('注册失败!');
	   	 }
	  }
	
		
	
	
	}
	





}
